package service.impl;

import dao.GgMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pojo.Gg;
import service.GgService;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 公告业务逻辑实现类
 */
@Service
public class GgServiceImpl implements GgService {

    @Autowired
    private GgMapper ggMapper;

    @Override
    public int add(Gg gg) {
        // 自动填充发布时间（如果未设置）
        if (gg.getPublishTime() == null) {
            gg.setPublishTime(LocalDateTime.now());
        }
        // 填充isShow默认值（对应数据库is_show=1）
        if (gg.getIsShow() == null) {
            gg.setIsShow(true);
        }
        // 填充sortOrder默认值
        if (gg.getSortOrder() == null) {
            gg.setSortOrder(0);
        }
        return ggMapper.add(gg);
    }

    @Override
    public List<Gg> findPublished() {
        return ggMapper.findPublished();
    }

    @Override
    public List<Gg> findAll() {
        return ggMapper.findAll();
    }

    @Override
    public Gg findById(Integer id) {
        return ggMapper.findById(id);
    }

    @Override
    public int update(Gg gg) {
        return ggMapper.update(gg);
    }

    @Override
    public int delete(Integer id) {
        return ggMapper.delete(id);
    }
}